package com.android.cherryboard.AddCherryboard;

import com.android.cherryboard.R;
import com.android.cherryboard.Task.AddCherryboardTask;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddCherryboardActivity extends Activity implements android.view.View.OnClickListener {

	private EditText etCherryboardTitle;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_cherryboard_view);
		
		
		setUpView();
		
		
		
	}

	private void setUpView() {
		// TODO Auto-generated method stub
		Button btnAddCherryboard = (Button)this.findViewById(R.id.button_add_cherryboard);
		btnAddCherryboard.setOnClickListener(this);
		etCherryboardTitle = (EditText)this.findViewById(R.id.editText_add_cherryboard_title);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.button_add_cherryboard:
			addCherryboard(v);
			break;

		default:
			break;
		}
	}

	private void addCherryboard(View v) {
		// TODO Auto-generated method stub
		if (isInputValid()) {
			
			AddCherryboardTask addCherryboardTask = new AddCherryboardTask(v);
 			addCherryboardTask.execute(etCherryboardTitle.getText().toString());
			
		}
	}

	private boolean isInputValid() {
		// TODO Auto-generated method stub
		String titleText = etCherryboardTitle.getText().toString();
		if (titleText.trim().length()<1) {
			return false;
		} else {
 			return true;
		}
	}

}
